package com.mars.foodserver.controller.admin;

import com.mars.foodserver.request.FoodRequest;
import com.mars.foodserver.request.FoodTypeRequest;
import com.mars.foodserver.response.result.R;
import com.mars.foodserver.service.IFoodTypeService;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wq
 * @since 2021-07-19
 */
@RestController
@RequestMapping("admin/foodType")
@AllArgsConstructor
public class AdminFoodTypeController {

    final IFoodTypeService foodTypeService;

    /**
     * 添加
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/add")
    public R add(@RequestBody FoodTypeRequest request) {
        foodTypeService.add(request);
        return R.success();
    }


    /**
     * 更新
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/update")
    public R update(@RequestBody FoodTypeRequest request) {
        foodTypeService.update(request);
        return R.success();
    }

    /**
     * 删除
     *
     * @param id ID
     * @return R
     */
    @GetMapping("/delete")
    public R delete(Integer id) {
        foodTypeService.delete(id);
        return R.success();
    }

    /**
     * 下拉列表
     *
     * @return R
     */
    @GetMapping("/list")
    public R foodTypeList() {
        return R.success(foodTypeService.foodTypeList());
    }

    /**
     * 详情
     *
     * @param id ID
     * @return R
     */
    @GetMapping("/detail")
    private R detail(Integer id) {
        return R.success(foodTypeService.detail(id));
    }


    /**
     * 分页
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/page")
    private R page(@RequestBody FoodTypeRequest request) {
        return R.success(foodTypeService.page(request));
    }

}
